package com.gongjian.utile.utile;



import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author 董浩
 */
public class Poi {
    //文件流
    InputStream inputStream;
    String name;
    private static final String EXCEL_XLS = "xls";
    private static final String EXCEL_XLSX = "xlsx";

    public Poi(InputStream inputStream,String name) {
        this.inputStream = inputStream;
        this.name=name;

    }
    /**
     * 判断Excel的版本,获取Workbook
     * @param
     * @return
     * @throws IOException
     */
    public Workbook getWorkbok() throws IOException{
        Workbook wb = null;
        if(name.endsWith(EXCEL_XLS)){
            //Excel 2003
            wb = new HSSFWorkbook(inputStream);
        }else if(name.endsWith(EXCEL_XLSX)){
            // Excel 2007/2010
            wb = new XSSFWorkbook(inputStream);
        }
        return wb;
    }



}
